package friot.service.cloud.controller;

import friot.model.iot.entity.IotThings;
import friot.service.cloud.service.IotThingsService;
import friot.utils.tools.JwtUtil;
import friot.utils.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author He Kuntao
 * @desc TODO
 * @date 2024/3/14 23:30
 */
@Slf4j
@RestController
@RequestMapping("/api/iot/things")
public class IotThingsController {

    @Resource
    private IotThingsService iotThingsService;

    /**
     * 获取当前ID设备的日志
     *
     * @return 日志列表
     */
    @GetMapping
    public Result listThings(HttpServletRequest request) {
        int userId = JwtUtil.parseTokenToUserId(request);
        List<IotThings> iotThings = iotThingsService.listThingsByUserId(userId);
        return Result.success(iotThings);
    }

}
